package org.abratuhi.kvngroupware.dalgen;

import java.util.Properties;

import org.abratuhi.kvngroupware.network.AbstractRequestMessageProceeder;
import org.abratuhi.kvngroupware.network.Client;
import org.abratuhi.kvngroupware.network.Message;
import org.abratuhi.kvngroupware.network.MessageSender;
import org.jdom.Element;

public class DalgenRequestMessageProceeder extends AbstractRequestMessageProceeder{
	MessageSender sender;
	Properties properties;
	
	DalgenDbMessageProceeder dbproceeder;
	
	public DalgenRequestMessageProceeder(MessageSender sender, Properties properties){
		this.sender = sender;
		this.properties = properties;
		this.dbproceeder = new DalgenDbMessageProceeder(properties);
	}

	@Override
	public void proceedMessage(Client client, Message message) {
		Element request = message.getRoot().getChild("request");
		String type = request.getAttributeValue("type");
		String action = request.getAttributeValue("action");
		
		if(type.equals("dalgen")
				&& action.equals("get")){
			Element[] words = dbproceeder.getWords(3);
			sender.sendMessage(sender.createMessage("type,action,status", "dalgen,get,ok", "", words));
		}
	}

}
